<template>
    <view>
        <!-- #ifdef MP-TOUTIAO -->
        <TtPageWatch ref="ttBox" :nowId="nowId" />
        <!-- #endif -->
    </view>
</template>

<script>
import TtPageWatch from './tt_page.vue'
export default {
    components: {
        TtPageWatch
    },
    data() {
        return {
            nowId: '',
        }
    },
    async onShow() {
        let obj = {
            'dev': 37,
            'qa': 27,
            'online': 27,
        }
        this.nowId = obj[getApp().globalData.PROFILE || 'dev']
        // 切换刷新
        //#ifdef MP-TOUTIAO
        await this.$nextTick()
        setTimeout(() => {
            this.$refs.ttBox && this.$refs.ttBox.reset()
        }, 100)

        //#endif
    },
    async onLoad(e) {
        if (e && e.batchId && !e.page) {
			setTimeout(() => {
				this.getBatchInfoMess(e.batchId, e)
			}, 300)
		}
    },
    methods: {
        async getShareBatchId() {
            let res = await this.zwyRequest({
                url: '/cdp/spread_channel/batch/generate',
                method: 'POST',
                data: {
                    title: '抖音专题页'
                }
            })
            if (res && res.batchId) {
                console.log('getShareBatchId', res);
                getApp().globalData.shareBatchId = res.batchId;
            }
        },
        		// 获取批次信息重定向到播放页
		async getBatchInfoMess(batchId, e) {
			try {
				let res = await this.zwyRequest({
					method: 'get',
					url: '/cdp/launch/getMediaSpreadInfo',
					data: {
						batchId: batchId
					}
				})

				if (res && res.mediaAccountSpreadBatchDTO && res.mediaAccountSpreadBatchDTO.batchId) {
					setTimeout(() => {
						let objMess = res.mediaAccountSpreadBatchDTO
						// 首页中转埋点计数
						this.$uma && this.$uma.trackEvent('Ume_PageView', {
							name: 'Ume_PageView_Into_Video'
						});
						let keyLink = ''
						if (e) {
							Object.keys(e).forEach(key => {
								if (key != 'batchId') {
									keyLink += `&${key}=${e[key]}`
								}
							})
						}
						console.log('keyLink------', keyLink)
						getApp().globalData.spreadMode = objMess.spreadMode || ''
						getApp().globalData.seqEpisodeListSwitch = objMess.seqEpisodeListSwitch || false
                        getApp().globalData.payAmountCloseSwitch = objMess.payAmountCloseSwitch || false
						getApp().globalData.spreadModeBatch = objMess.spreadMode || ''
						uni.setStorageSync('adMess', JSON.stringify({
							...e,
							keepDate: new Date()
						}))
						uni.setStorageSync('adMessLinkKey', keyLink)
						uni.setStorageSync('adMessLinkKeyAll', `/pages/video/video?fakeId=${res.fakeId}&batchId=${objMess.batchId}${keyLink}`)
						//  #ifdef MP-KUAISHOU
						this.zwyRouter(`/pages/video/video?fakeId=${res.fakeId}&batchId=${objMess.batchId}&compilationId=${objMess.compilationsId || ''}&enterSequence=${objMess.enterSequence || 0}&userLockSequenc=${objMess.stickingPointSequence || ''}&userLockId=${objMess.kuaiShouSevAccount || ''}&buySpace=${objMess.buySpace || ''}`)
						// #endif
						// #ifdef MP-TOUTIAO
						this.zwyRouter(`/pages/video/video?fakeId=${res.fakeId}&batchId=${objMess.batchId}`)
						// #endif

					}, 600)
				}
			} catch (error) {
				console.log(error)
			}
		},
    },
    onShareAppMessage: async function () {
        //#ifdef MP-TOUTIAO
        await this.getShareBatchId()
        //#endif
        console.log(122112)
        var shareJson = {
            path: '/pages/specialPage/specialPage',
            data: {
                page: 'mine',
                sharePosition: '/pages/specialPage/specialPage',
                from: '/position/specialPage/specialPage',
                sharePage: '/pages/specialPage/specialPage'
            }
        };
        // 达人分享批次
        // 注释以前的逻辑
        let shareBatchId = uni.getStorageSync('shareBatchId');
        if (shareBatchId && !getApp().globalData.shareBatchId) {
            getApp().globalData.shareBatchId = shareBatchId
        }
        shareJson.title = '🔥SSS级火爆爽剧，不看血亏❗';
        shareJson.type = 'dySpecial'
        shareJson.introduce = '🔞抖音500w播放的劲爆爽剧，看过的人都说很好看，我想和你一起看❗'
        shareJson.imageUrl = `https://res.qiguoread.com/staticResources/fellow_townsman/image/sPage_share2.png`
        return this.formatShare(shareJson);
    }
};
</script>

